package com.yzt.zhuju.network.biz;

import com.alibaba.fastjson.JSONObject;
import com.yzt.zhuju.network.NetLayer;
import com.yzt.zhuju.network.apiconfig.DynamicUrlConstant;
import com.yzt.zhuju.network.entity.DynamicCommentBean;

import rx.Observable;
import rx.Observer;

/**
 * author : bob
 * date   : 2023/2/27
 * desc   : 动态接口模块
 */
public class DynamicModule extends BaseModule {

    /**
     * 动态列表
     */
    public void dynamicList(int page, int size, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("current", page);
        json.put("pageSize", size);
        json.put("type", 2);
//        json.put("keyword", keyword);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_LIST);
    }

    /**
     * 动态列表
     */
    public void dynamicList(String userId, int page, int size, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("current", page);
        json.put("pageSize", size);
        json.put("userId", userId);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_LIST);
    }

    /**
     * 动态详情
     */
    public void dynamicDetail(String dynamicId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("momentId", dynamicId);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicDetail(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_DETAIL);
    }

    /**
     * 添加动态
     */
    public void dynamicAdd(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicAdd(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_ADD);
    }

    /**
     * 动态删除
     */
    public void dynamicDel(String dynamicId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("communityId", dynamicId);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicDel(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_DEL);
    }

    /**
     * 动态点赞
     */
    public void dynamicLike(String dynamicId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("momentId", dynamicId);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicLike(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_LIKE);
    }

    /**
     * 取消点赞
     */
    public void dynamicUnLike(String dynamicId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("momentId", dynamicId);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicUnLike(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_UN_LIKE);
    }

    /**
     * 动态评论列表
     */
    public void dynamicCommentList(String dynamicId, int page, int size, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("current", size);
        json.put("momentId", dynamicId);
        json.put("pageSize", page);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicCommentList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_COMMENT_LIST);
    }

    /**
     * 动态评论添加
     */
    public void dynamicCommentAdd(String dynamicId, DynamicCommentBean bean, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("momentId", dynamicId);
        json.put("content", bean.getContent());
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicCommentAdd(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_COMMENT_ADD);
    }

    /**
     * 动态评论添加
     */
    public void dynamicCommentAddChild(String dynamicId, DynamicCommentBean bean, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("momentId", dynamicId);
        json.put("content", bean.getContent());
        json.put("commentId", bean.getCommentId());
        json.put("replyUserId", bean.getReplyUid());
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicCommentReply(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_COMMENT_ADD);
    }

    /**
     * 动态评论点赞
     *
     * @param dynamicId      动态ID
     * @param type           1 评论 2 子评论
     * @param commentId      评论id
     * @param childCommentId 子评论id
     * @param status         点赞状态 true 点赞 false 取消点赞
     */
    public void dynamicCommentLike(int type, String dynamicId, String commentId, String childCommentId, boolean status, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("dynId", dynamicId);
        json.put("commentId", commentId);
        if (type == 2) {
            json.put("replyCommentId", childCommentId);
        }
        json.put("status", status ? 1 : 0);
        Observable observable = NetLayer.getInstance().getDynamicService().dynamicCommentLike(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_DYNAMIC_COMMENT_LIKE);
    }

    /**
     * 我参与的活动
     */
    public void activityList(int page, int size, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("current", page);
        json.put("pageSize", size);
        Observable observable = NetLayer.getInstance().getDynamicService().activityList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.GET_ACTIVITY_LIST);
    }

    /**
     * 创建组局
     */
    public void createGame(JSONObject json, Observer observer) {
        Observable observable;
        if (json.get("gameId") != null) {
            observable = NetLayer.getInstance().getDynamicService().createGame(getRequestBody(json));
            toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_EDIT);
        } else {
            observable = NetLayer.getInstance().getDynamicService().createGame(getRequestBody(json));
            toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_CREATE);
        }
    }

    /**
     * 游戏详情
     */
    public void getGameDetail(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().getGameDetail(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_DETAIL);
    }

    /**
     * 游戏房间玩家
     */
    public void getGamePlayUser(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().getGamePlayUser(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_PLAY_LIST);
    }

    /**
     * 开始游戏
     */
    public void startGame(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().startGame(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_START);
    }

    /**
     * 结束游戏
     */
    public void endGame(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().endGame(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_END);
    }

    /**
     * 下一关游戏
     */
    public void gameNextLevel(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().gameNextLevel(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_NEXT_LEVEL);
    }

    /**
     * 更换主持人
     */
    public void exchangeHost(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().exchangeHost(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_EXCHANGE_HOST);
    }

    /**
     * 取消游戏
     */
    public void cancelGame(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().cancelGame(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_CANCEL);
    }

    /**
     * 游戏详情
     */
    public void joinGame(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().joinGame(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_JOIN);
    }


    /**
     * 离开游戏
     */
    public void quitGame(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().quitGame(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_QUIT);
    }

    /**
     * 离开房间
     */
    public void quitRoom(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().quitRoom(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_QUIT);
    }

    /**
     * 进入房间
     */
    public void enterRoom(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().enterRoom(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_ENTER_ROOM);
    }

    /**
     * 踢出用户
     */
    public void gameKickUser(JSONObject json, Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().gameKickUser(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_GAME_KICK_USER);
    }

    /**
     * 剧本列表
     */
    public void scriptList(String activityId, int page, int size, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("activityId", activityId);
        json.put("current", page);
        json.put("pageSize", size);
        Observable observable = NetLayer.getInstance().getDynamicService().scriptList(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_SCRIPT_LIST);
    }

    /**
     * 剧本详情
     */
    public void scriptDetail(int gameId, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("gameId", gameId);
        Observable observable = NetLayer.getInstance().getDynamicService().scriptDetail(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_SCRIPT_DETAIL);
    }

    /**
     * 选择/更换剧本
     */
    public void scriptSelect(JSONObject json,  Observer observer) {
        Observable observable = NetLayer.getInstance().getDynamicService().scriptSelect(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_SCRIPT_SET);
    }

    /**
     * 发送红包
     */
    public void addRedPkg(JSONObject json, Observer observer) {

        if ((boolean) json.get("redType")) {
            Observable observable = NetLayer.getInstance().getDynamicService().addLuckRedPkg(getRequestBody(json));
            toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_LUCK_RED_PKG);
        } else {
            Observable observable = NetLayer.getInstance().getDynamicService().addExclusiveRedPkg(getRequestBody(json));
            toSubscribe2Filter(observable, observer, DynamicUrlConstant.POST_EXCLUSIVE_RED_PKG);
        }
    }

    /**
     * 红包封面
     */
    public void getRedPacketInfo(String id, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("redPacketId", id);
        Observable observable = NetLayer.getInstance().getDynamicService().getRedPacketInfo(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.API_RED_PKG_INFO);
    }

    /**
     * 领取红包
     */
    public void openRedPacketInfo(String id, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("redPacketId", id);
        Observable observable = NetLayer.getInstance().getDynamicService().openRedPacketInfo(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.API_OPEN_RED_PKG);
    }

    /**
     * 红包领取详情
     */
    public void getRedPacketGetInfo(String id, Observer observer) {
        JSONObject json = new JSONObject();
        json.put("redPacketId", id);
        Observable observable = NetLayer.getInstance().getDynamicService().getRedPacketGetInfo(getRequestBody(json));
        toSubscribe2Filter(observable, observer, DynamicUrlConstant.API_RED_PKG_GET_INFO);
    }
}
